<script setup>
import { forEach } from 'lodash-es';
import { useWatch } from '@/hooks/useWatch';

const props = defineProps({
  data: { type: Array, default: () => null },
  buildData: { type: Array, default: () => null },
  showYear: { type: Boolean, default: false },
});
const tree = ref(null);

const isdisabledFn = () => {
  return true;
};
const defaultProps = {
  // 默认设置
  children: 'children',
  label: 'name',
  disabled: isdisabledFn,
};

useWatch(
  () => props.data,
  n => {
    if (!n) {
      forEach(tree.value, n => {
        nextTick(() => {
          if (n) n.setCheckedKeys([]);
        });
      });
    }
  },
  { deep: true, immediate: true },
);
</script>
<template>
  <div>
    <div v-for="(item, index) in data" :key="index">
      <div v-if="showYear" class="u-prim-text">
        考核年度：
        <span class="u-primary">{{ item?.checkYear ?? '-' }}</span>
      </div>
      <div class="ad-wrapper u-prim-text">
        <div class="khzb-left">
          <div class="title-top u-df-st">
            {{ item?.dateType === 'FIRST' ? '监测开始时间：' : '变更时间：' }}
            <span class="u-primary">{{ item?.startTime ?? '-' }}</span>
          </div>
          <el-table :data="item?.index ?? []" :height="350" border>
            <el-table-column label="能耗类型" align="center" prop="energyTypeInfo">
              <template slot-scope="scope">
                {{ scope.row?.energyTypeInfo || scope.row?.energyType }}
              </template>
            </el-table-column>
            <el-table-column prop="upperLimitValue" label="约束值" align="center">
              <template slot-scope="scope">
                <span :class="scope.row?.upperLimitValueChange ? 'red' : ''">
                  {{ scope.row?.upperLimitValue }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="basisValue" label="基准值" align="center">
              <template slot-scope="scope">
                <span :class="scope.row?.basisValueChange ? 'red' : ''">
                  {{ scope.row?.basisValue }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="guideValue" label="引导值" align="center">
              <template slot-scope="scope">
                <span :class="scope.row?.guideValueChange ? 'red' : ''">
                  {{ scope.row?.guideValue }}
                </span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="khzb-right">
          <div class="title-top u-df-st">关联区域</div>
          <el-tree
            ref="tree"
            :data="buildData ?? []"
            :props="defaultProps"
            show-checkbox
            :default-checked-keys="item.areaIds"
            node-key="id"
            class="u-p20 mtree"
          >
            <span class="custom-tree-node u-fs14" slot-scope="{ node, data }">
              <!-- <ToolTip class="tree-lable u-pr20" :content="data.name" effect="dark" /> -->
              <span class="tree-lable u-pr20">{{ data.name }}</span>
            </span>
          </el-tree>
        </div>
      </div>
      <div>
        <el-input type="textarea" :rows="3" v-model="item.noteInfo" :disabled="true"></el-input>
      </div>
      <div class="u-p20 u-prim-text" style="padding-left: 0">
        <span class="u-pr20">操作人：{{ item?.createBy ?? '-' }}</span>
        <span>操作时间：{{ item?.createTime ?? '-' }}</span>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.ad-wrapper {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin: 20px 0;
  .title-top {
    width: 100%;
    padding-left: 20px;
    height: 48px;
  }
  .khzb-left {
    width: calc(60% + 22px);
    margin-right: 20px;
  }
  .khzb-right {
    width: calc(40% - 22px);

    height: 400px;
    overflow-y: scroll;
    .title-top {
      border-bottom: 1px solid #374468;
    }
  }
}
.app-dark {
  .khzb-left {
    .title-top {
      background: #242b41;
      border: 1px solid #374468;
      border-bottom: none;
    }
  }
  .khzb-right {
    border: 1px solid #374468;
    .title-top {
      background: #242b41;
      border-bottom: 1px solid #374468;
    }
  }
}
.app-light {
  .khzb-left {
    .title-top {
      background: #f5f7fa;
      border: 1px solid #eee;
      border-bottom: none;
    }
  }
  .khzb-right {
    border: 1px solid #eee;
    .title-top {
      background: #f5f7fa;
      border-bottom: 1px solid #eee;
    }
  }
}
.red {
  color: #ff0000;
}
.mtree {
  height: calc(100% - 48px);
  overflow-y: scroll;
}
</style>
